package com.wodsy.phoenix.dataservice.payc.util;

import java.text.MessageFormat;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Created by jiwenku on 2015/5/22.
 */
public class Messages {
    private static final String BUNDLE_NAME = "config";//$NON-NLS-1$
    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

    private Messages() {}

    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        }
        catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }

    public static String getString(String key, String[] paras) {
        try {
            String message = RESOURCE_BUNDLE.getString(key);
            return MessageFormat.format(message, paras);
        }
        catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }

    public static String getString(String key, List arg) {
        try {
            if (!arg.isEmpty()) {
                String[] paras = new String[arg.size()];
                for (int i = 0; i < arg.size(); i++)
                    paras[i] = (String) arg.get(i);
                return getString(key, paras);
            }
            return "";
        }
        catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }

    public static String getStringArrayRandom(String key){
        String values = "";
        try{
            values = getString(key);
        }catch(Exception e){
            e.printStackTrace();
        }
        return values;
    }
}
